package REUtils;

import java.util.regex.*;


public class TextUtils {

	public static String[] CQitems=new String[40] ;  //CashFlow Quarter
	public static String[] ISQitems=new String[35] ; //ISQ item
	public static String[] BSQitems=new String[54] ; //BSQ item
	public static String[] BAitems=new String[57] ;  //BASIC item
	public static String[] TW50items = new String[50];
	
	public static void initTW50items(){
		TW50items[0]="3474";  //華亞科
		TW50items[1]="8046";  //南電
		TW50items[2]="4938";  //和碩
		TW50items[3]="3481";  //奇美電子
		TW50items[4]="2330";  //臺積電
		TW50items[5]="2303";  //聯電
		TW50items[6]="2882";  //國泰金
		TW50items[7]="2357";  //華碩
		TW50items[8]="1303";  //南亞塑膠
		TW50items[9]="2883";  //開發金
		TW50items[10]="1301"; //臺灣塑膠
		TW50items[11]="2002"; //中國鋼鐵
		TW50items[12]="2311"; //日月光
		TW50items[13]="2317"; //鴻海
		TW50items[14]="1402"; //遠東新
		TW50items[15]="2324"; //仁寶
		TW50items[16]="2892"; //第一金
		TW50items[17]="2880"; //華南金
		TW50items[18]="2888"; //新光金
		TW50items[19]="2801"; //彰銀
		TW50items[20]="1216"; //統一企業
		TW50items[21]="1101"; //臺灣水泥
		TW50items[22]="1102"; //亞洲水泥
		TW50items[23]="2382"; //廣達
		TW50items[24]="2308"; //台達電
		TW50items[25]="1326"; //臺灣化纖
		TW50items[26]="2886"; //兆豐金
		TW50items[27]="2891"; //中信金
		TW50items[28]="2325"; //矽品
		TW50items[29]="2353"; //宏碁
		TW50items[30]="1722"; //台灣肥料
		TW50items[31]="2105"; //正新橡膠
		TW50items[32]="2412"; //中華電信
		TW50items[33]="2409"; //友達
		TW50items[34]="2301"; //光寶科
		TW50items[35]="9904"; //寶成工業
		TW50items[36]="2912"; //統一超商
		TW50items[37]="2354"; //鴻準
		TW50items[38]="2347"; //聯強
		TW50items[39]="3045"; //台灣大哥大
		TW50items[40]="2454"; //聯發科
		TW50items[41]="2881"; //富邦金
		TW50items[42]="2448"; //晶元
		TW50items[43]="4904"; //遠傳
		TW50items[44]="2885"; //元大金
		TW50items[45]="2498"; //宏達電
		TW50items[46]="2890"; //永豐金控
		TW50items[47]="3231"; //緯創
		TW50items[48]="6505"; //台塑化
		TW50items[49]="5854"; //合庫          

		
	}
	
	
    public static void initBSQitems(){
  	  BSQitems[0] = "現金及約當現金 ";
  	  BSQitems[2] = "短期投資";
  	  BSQitems[3] = "應收帳款及票據 ";
  	  BSQitems[4] = "其他應收款";
  	  BSQitems[5] = "短期借支";
  	  BSQitems[6] = "存貨";
  	  BSQitems[7] = "在建工程";
  	  BSQitems[8] = "預付費用及預付款 ";
  	  BSQitems[9] = "其他流動資產 ";
  	  BSQitems[10] = "流動資產 ";
  	  BSQitems[11] = "長期投資";
  	  BSQitems[12] = "土地成本";
  	  BSQitems[13] = "房屋及建築成本";
  	  BSQitems[14] = "機器及儀器設備成本";
  	  BSQitems[15] = "其他設備成本";
  	  BSQitems[16] = "固定資產重估增值";
  	  BSQitems[17] = "固定資產累計折舊";
  	  BSQitems[18] = "固定資產損失準備";
  	  BSQitems[19] = "未完工程及預付款 ";
  	  BSQitems[20] = "固定資產";
  	  BSQitems[21] = "遞延資產";
  	  BSQitems[22] = "無形資產";
  	  BSQitems[23] = "什項資產 ";
  	  BSQitems[24] = "其他資產";
  	  BSQitems[25] = "資產總額";
  	  BSQitems[26] = "短期借款";
  	  BSQitems[27] = "應付商業本票";
  	  BSQitems[28] = "應付帳款及票據 ";
  	  BSQitems[29] = "應付費用";
  	  BSQitems[30] = "預收款項";
  	  BSQitems[31] = "其他應付款";
  	  BSQitems[32] = "應付所得稅";
  	  BSQitems[33] = "一年內到期長期負債";
  	  BSQitems[34] = "其他流動負債";
  	  BSQitems[35] = "流動負債";
  	  BSQitems[36] = "長期負債";
  	  BSQitems[37] = "遞延貸項 ";
  	  BSQitems[38] = "退休金準備";
      BSQitems[39] = "遞延所得稅";
      BSQitems[40] = "土地增值稅準備";
      BSQitems[41] = "各項損失準備";
      BSQitems[42] = "什項負債";
      BSQitems[43] = "其他負債及準備";
      BSQitems[44] = "負債總額";
      BSQitems[45] = "股東權益總額";
      BSQitems[46] = "普通股股本";
      BSQitems[47] = "特別股股本";
      BSQitems[48] = "資本公積";
      BSQitems[49] = "法定盈餘公積";
      BSQitems[50] = "特別盈餘公積";
      BSQitems[51] = "未分配盈餘";
      BSQitems[52] = "長期投資評價損失";
      BSQitems[53] = "負債及股東權益總額";
  	 	  
		      }

      public static void initISQitems(){
    	  ISQitems[0] = "營業收入淨額";
    	  ISQitems[2] = "營業成本";
    	  ISQitems[3] = "營業毛利";
    	  ISQitems[4] = "聯屬公司間未實現銷貨";
    	  ISQitems[5] = "營業費用";
    	  ISQitems[6] = "營業利益";
    	  ISQitems[7] = "利息收入";
    	  ISQitems[8] = "投資收入／股利收入";
    	  ISQitems[9] = "處分投資利得 ";
    	  ISQitems[10] = "投資跌價損失回轉";
    	  ISQitems[11] = "處分資產利得";
    	  ISQitems[12] = "存貨跌價損失回轉";
    	  ISQitems[13] = "兌換盈益";
    	  ISQitems[14] = "其他收入";
    	  ISQitems[15] = "營業外收入合計";
    	  ISQitems[16] = "利息支出";
    	  ISQitems[17] = "投資損失";
    	  ISQitems[18] = "處分投資損失";
    	  ISQitems[19] = "投資跌價損失";
    	  ISQitems[20] = "處分資產損失";
    	  ISQitems[21] = "兌換損失";
    	  ISQitems[22] = "資產評價損失";
    	  ISQitems[23] = "其他損失";
    	  ISQitems[24] = "營業外支出合計";
    	  ISQitems[25] = "稅前淨利";
    	  ISQitems[26] = "所得稅費用";
    	  ISQitems[27] = "經常利益";
    	  ISQitems[28] = "停業部門損益";
    	  ISQitems[29] = "非常項目";
    	  ISQitems[30] = "累計影響數";
    	  ISQitems[31] = "本期稅後淨利";
    	  ISQitems[32] = "每股盈餘(元)";
    	  ISQitems[33] = "加權平均股本";
    	  ISQitems[34] = "當季特別股息負債";
		      }

      public static void initBAitems(){

    	  BAitems[0] ="最近交易日";
    	  BAitems[1] ="開盤價";
    	  BAitems[2] ="最高價";
    	  BAitems[3] ="最低價";
    	  BAitems[4] ="收盤價";
    	  BAitems[5] ="漲跌";
    	  BAitems[6] ="一年內最高價";
    	  BAitems[7] ="一年內最低價";
    	  BAitems[8] ="本益比";
    	  BAitems[9] ="一年內最大量";
    	  BAitems[10] ="一年內最低量";
    	  BAitems[11] ="成交量";
    	  BAitems[12] ="同業平均本益比";
    	  BAitems[13] ="一年來最高本益比";
    	  BAitems[14] ="一年來最低本益比";
    	  BAitems[15] ="盤後量";
    	  BAitems[16] ="總市值";
    	  BAitems[17] ="85年來最高總市值";
    	  BAitems[18] ="85年來最低總市值";
    	  BAitems[19] ="今年以來";
    	  BAitems[20] ="每股淨值(元)";
    	  BAitems[21] ="貝他值";
    	  BAitems[22] ="最近一週";
    	  BAitems[23] ="每人營收(仟元)";
    	  BAitems[24] ="標準差";
    	  BAitems[25] ="最近一個月";
    	  BAitems[26] ="每股營收(元)";
    	  BAitems[27] ="最近二個月";
    	  BAitems[28] ="負債比例";
    	  BAitems[29] ="最近三個月";
    	  BAitems[30] ="股價淨值比";
    	  BAitems[31] ="營收市值比";
    	  BAitems[32] ="股本(億)";
    	  BAitems[33] ="營業毛利率";
    	  BAitems[34] ="現金股利(元)";
    	  BAitems[35] ="成立時間";
    	  BAitems[36] ="營業利益率";	
    	  BAitems[37] ="股票股利";
    	  BAitems[38] ="初次上市(櫃)日期";
    	  BAitems[39] ="稅前淨利率";
    	  BAitems[40] ="盈餘配股";
    	  BAitems[41] ="股務代理";
    	  BAitems[42] ="資產報酬率";	
    	  BAitems[43] ="公積配股";
    	  BAitems[44] ="董事長";
    	  BAitems[45] ="股東權益報酬率";
    	  BAitems[46] ="現金增資(億)";
    	  BAitems[47] ="總經理";
    	  BAitems[48] ="發言人";
    	  BAitems[49] ="營收比重";
    	  BAitems[50] ="公司電話";
    	  BAitems[51] ="網址";
    	  BAitems[52] ="公司地址";
    	  BAitems[53] ="最高總市值";
    	  BAitems[54] ="最低總市值";
    	  BAitems[55] ="股票股利";	
    	  BAitems[56] ="現金股利";
    	  	
      }
      public static void initCQitems(){
    	//CQitems[0] ="期別";
    	CQitems[1] ="稅後淨利";
    	CQitems[2] ="不動用現金之非常損益";
    	CQitems[3] ="折舊";
    	CQitems[4] ="攤提";
    	CQitems[5] ="投資收益－權益法";
    	CQitems[6] ="投資損失－權益法";
    	CQitems[7] ="現金股利收入－權益法";
    	CQitems[8] ="短期投資處分損(益)";
    	CQitems[9] ="固定資產處分損(益)";
    	CQitems[10] ="長期投資處分損(益)";
    	CQitems[11] ="準備提列(迴轉)";
    	CQitems[12] ="應收帳款(增)減";
    	CQitems[13] ="存貨(增)減";
    	CQitems[14] ="應付帳款增(減)";
    	CQitems[15] ="其他調整項─營業";
    	CQitems[16] ="來自營運之現金流量";
    	CQitems[17] ="短期投資出售(新購)";
    	CQitems[18] ="出售長期投資價款";
    	CQitems[19] ="長期投資(新增)";
    	CQitems[20] ="處分固定資產價款";
    	CQitems[21] ="固定資產(購置)";
    	CQitems[22] ="其他調整項─投資";
    	CQitems[23] ="投資活動之現金流量";
    	CQitems[24] ="現金增資";
    	CQitems[25] ="支付現金股利";
    	CQitems[26] ="支付董監酬勞員工紅利";
    	CQitems[27] ="短期借款新增(償還)";
    	CQitems[28] ="長期借款新增(償還)";
    	CQitems[29] ="發行公司債";
    	CQitems[30] ="償還公司債";
    	CQitems[31] ="庫藏股票減(增)";
    	CQitems[32] ="其他調整項─理財";
    	CQitems[33] ="理財活動之現金流量";
    	CQitems[34] ="匯率影響數";
    	CQitems[35] ="本期產生現金流量";
    	CQitems[36] ="期初現金約當現金";
    	CQitems[37] ="期末現金及約當現金";
    	CQitems[38] ="本期支付利息";
    	CQitems[39] ="本期支付所得稅";
    }

	public static  String getCQitems(int i) {
		if(i>39){return "Error CFSQitems index";}
		else{
		    return CQitems[i];
		   }
		}
	public static  String getISQitems(int i) {
		if(i>34){return "Error ISQitems index";}
		else{
	    return ISQitems[i];
		}
	  }
	
	public static  String getBSQitems(int i) {
		if(i>53){return "Error BSQitems index";}
		else{
	    return BSQitems[i];
		}
	  }
	
	public static  String getBAitems(int i) {
		if(i>57){return "Error BSQitems index";}
		else{
	    return BAitems[i];
		}
	  }
	
	public static boolean hasTenDigits(String s) {
		  return s.matches(".*[0-9]{10}.*");
		}
	
	public static boolean containsTenDigits(String str) {
		  Pattern patt = Pattern.compile(".*?[0-9]{10}.*");
		  Matcher m = patt.matcher(str);
		  return m.find();//matches();
		}

	public static boolean IsNegDigit(String str){
		if(str == null){return false;}
		
		Pattern patt = Pattern.compile("^[-]");
	    Matcher m = patt.matcher(str);
		return m.find();
	}

    
	public static float Str2Value(String Strinput){
		
		if(Strinput == null){
			return 0;
		}
			
		
		float finput=0;
		String Strinput1 = Strinput.replaceAll(",", "");	
		Strinput1 = Strinput1.replaceAll("/+", "");
	
		//String Strtt = "1235%";
		//System.out.println(IsNegDigit(Strtt));
	
		if(IsNegDigit(Strinput1)){
		 finput = -1;
		}
		else if(Strinput1.matches("[0-9]%$")){
		 finput = 0;	
		}else{
		 finput = Strinput1.equals("")?0:Float.parseFloat(Strinput1); //float = 4bytes
		}
		
		//if(isNoNumberAtBeginning(Strinput)){finput= 55;}
		
		try{
			if(Strinput.equals("N/A")){finput=0;}
						
		}catch (NumberFormatException e){
			showMsg.ERR("Str2Value: You has no input");
		}
			
		return finput ;
	}
	

	
}

//////////////////////////////////////////////////////
